<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="hardcode2013.*" %>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
    
    <script type="text/javascript">
    function floatInputOnChange(input) {
 	   if (! input.value.match("^[0-9]*(\.[0-9]{1,2})?$")) input.value = "";
    }
    function floatInputOnKeyPress(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
           return false;
        else
	        return true;
    }
    </script>
  </head>  
  
  <body>
    <%@include file="include_header.jsp" %>
  
	<%
	String itemKeyStr = request.getParameter("item");
  	
	if (profile != null && itemKeyStr != null) {
		ItemProfile item = ItemServ.getItemProfile(itemKeyStr);
  		if (item != null) {
			%>
			<fieldset>
				<legend>Edit Item: <%= EncodeUtil.encodeHtml(item.getTitle()) %></legend>
				<form action="/item" method="post">
					Title: <input type="text" name="title" value="<%= EncodeUtil.encodeHtml(item.getTitle()) %>"><br>
					Description:<br><textarea name="description" rows="5" cols="50"><%= EncodeUtil.encodeHtml(item.getDescription()) %></textarea><br>
					Price: $<input type="text" name="price" onchange="return floatInputOnChange(this);" onkeypress="return floatInputOnKeyPress(event);" value="<%= EncodeUtil.encodeHtml(item.getPrice()) %>"><br>
					Expiration Date: <input type="date" name="expiration_date" value="<%= EncodeUtil.encodeHtml(item.getExpirationDateOnly()) %>">
					<input type="time" name="expiration_time" value="<%= EncodeUtil.encodeHtml(item.getExpirationTimeOnly()) %>"><br>
					(If you can't see the date/time selector, use format: yyyy-mm-dd , hh:mm)<br>
					<input type="hidden" name="item_key" value="<%= EncodeUtil.encodeHtml(item.getKeyStr()) %>">
					<input type="hidden" name="action" value="edit_item">
					<input type="hidden" name="redirect" value="/myitems.jsp">
					<input type="hidden" name="redirect_error" value="<%= "/edit_item.jsp?item=" + EncodeUtil.encodeUrl(itemKeyStr) %>">
					<input type="hidden" name="auth_key" value="<%= SessionUtil.getAuthKey(request) %>">
					<input type="submit" value="Edit" />
				</form>
			</fieldset>
			<%
		}
	}
	%>
  </body>
</html>